@layout("/common/_container.html"){
<div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto">
	  <div class="layui-form-item">
	  	<label class="layui-form-label">用户名：</label>
	    <div class="layui-input-inline">
         	<input type="text" name="userName" id="userName" autocomplete="off"  placeholder="用户名" class="layui-input" >
        </div>
	    <div class="layui-inline">
	      	<label class="layui-form-label">认证状态：</label>
			<div class="layui-input-block">
			 	  <select name="authState" id="authState">
			       <option value="">资质认证</option>
			       <option value="0">待审核</option>
			       <option value="1">审核通过</option>
			       <option value="2">驳回</option>
			     </select>
			</div>
	    </div>
	     <div class="layui-inline">
	     	<label class="layui-form-label">资质等级：</label>
	     	<div class="layui-input-block">
				<select name="mappingGrade" id="mappingGrade">
		       		<option value="">资质等级</option>
		       		<option value="1">甲级</option>
		      		<option value="2">乙级</option>
		       		<option value="3">丙级</option>
		       		<option value="4">丁级</option>
		     	</select>
			</div>
	     </div>
       </div>
         <div class="layui-form-item">
	     	<label class="layui-form-label">区域：</label>
	     	<div class="layui-input-inline" style="width:120px">
	     	<select name="province" id="provinces" lay-filter="changeProvince">
            	<option>请选择省</option>
            </select>
            </div>
          <div class="layui-input-inline" style="width:120px">
	        <select name="city" id="citys" lay-filter="changecity">
      			<option>请选择市</option>
    		</select>
    		</div>
    	<div class="layui-input-inline" style="width:120px">
    			<select name="area" id="areas">
      			 <option>请选择区</option>
   				</select>
	        </div>
	     
	     <div class="layui-inline">
             <label class="layui-form-label">提交时间：</label>
             <div class="layui-input-inline" style="width:120px">
             	<input type="text" class="layui-input" id="test-laydate-start" name="startTime" placeholder="开始日期"  autocomplete="off" >
             </div>
             <div class="layui-form-mid">
               -
             </div>
             <div class="layui-input-inline" style="width:120px">
               <input type="text" class="layui-input" id="test-laydate-end" name="endTime" placeholder="结束日期"  autocomplete="off" >
          </div>
         </div>
	    <div class="layui-inline">
	      <button class="layui-btn layuiadmin-btn-useradmin" data-type="reload" style="width:68px">
	        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
	      </button>
	    </div>
	     </div>
	   </div>
  <div class="layui-card-body">
  <table class="layui-hidden" id="table" lay-filter="table"></table>
  	<script type="text/html" id="oper">
			{{#  if(d.authState =='待审核'){ }}
		  	@if(shiro.hasPermission("/auth/review")){
  			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="review" title="审核">审核</a>
			@}
         {{#  } else { }}    
			@if(shiro.hasPermission("/auth/detail")){  
			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail" title="查看">查看</a>
			@}
			{{#  } }}
			
	</script>
		<script type="text/html" id="area">
				{{# if(d.province==d.city){}}
                 <div class="layui-text">
                  {{d.province}}{{d.area}}
                     </div>
               {{# }else{}}
             		<div class="layui-text">
             		{{d.province}}{{d.city}}{{d.area}}
                  </div>
                {{#  } }}
	</script>
  </div>
  	<table class="layui-hidden" id="table" lay-filter="table"></table>
  	</div>
<script>
layui.config({
	base: Feng.ctxPath + "/static/layuiadmin/" //静态资源所在路径
}).extend({
	index: 'lib/index' //主入口模块
}).use(['index', 'layer','table', 'form','laydate'],function(){
	var $ = layui.$
  	,form = layui.form
  	,table = layui.table
	,laydate=layui.laydate;
	
	var provinceAry = ChinaCity.getProvince();
	var provinceStr = '<option>请选择省</option>';
	$.each(provinceAry,function(i,val){
		provinceStr+='<option>'+val+'</option>'
	});
	 $("#provinces").html(provinceStr);
	form.render('select');
	   
	var province="";
	form.on('select(changeProvince)', function(data){
		 $("#areas").html("'<option>请选择区</option>'");
	     province = data.value;
		var cityAry = ChinaCity.getCity(province);
		var str = "<option>请选择市</option>";
		$.each(cityAry,function(i,val){ 
			str += '<option>' + val + '</option>';
		});
		$("#citys").html(str);
		 form.render('select');
	});
	
	form.on('select(changecity)',function(data){
		var city=data.value;
		var areaAry=ChinaCity.getArea(province,city);
		var str="<option>请选择区</option>";
		$.each(areaAry,function(i,val){
			str+= '<option>' + val + '</option>';
		})
		$("#areas").html(str);
		form.render('select');
	})
	
	
	
	var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
	table.render({
	    elem: '#table'
	    ,url: Feng.ctxPath + '/auth/list'
	    ,cellMinWidth: 100
	    ,height: 'full-168' //设置高度
	    ,cols: [[
	    	{title:'序号',type:'numbers'},
	        {title: '用户名', field: 'userName'},
	        {title: '用户机构', field: 'organName'},
	        {title: '区域',toolbar: '#area'},
	        {title: '手机号码', field: 'legalPersonPhone'},
	        {title: '资质等级', field: 'mappingGrade'},
	        {title: '认证状态', field: 'authState'},
	      /*   {title: '账号数/正常数', field: 'legalPersonName'}, */
	        {title: '提交时间', field: 'updateTime'},
	        {title: '操作',fixed: 'right', width:140, align:'center',fixed: 'right', toolbar: '#oper'}
	    ]]
	    ,page:true
	    ,loading:true
	    ,text: {
	        none: '暂无相关数据' 
	      }
	    ,done: function(res){
	    	layer.close(loadingIndex);
        }
	});
	
	//事件
	var active = {
		//加载
	   	reload: function(){
	       var userName=$("#userName").val();
	       var authState=$("#authState").val();
	       var mappingGrade=$("#mappingGrade").val();
	       var province=ifNull($("#provinces option:selected").html());
	       var city=ifNull($("#citys option:selected").html());
	       var area=ifNull($("#areas option:selected").html());
	       var startTime=$("#test-laydate-start").val();
	       var endTime=$("#test-laydate-end").val();
	       var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
	       //执行表格重载
	       table.reload('table', {
	    	 height: 'full-168' //设置高度
	    	 ,where: {
	    		 userName:userName,
	    		 authState:authState,
	    		 mappingGrade:mappingGrade,
	    		 province:province,
	    		 city:city,
	    		 area:area,
	    		 startTime:startTime,
	    		 endTime:endTime
	         }
	       ,page:true
	       ,done: function(res){
		    	layer.close(loadingIndex);
	        }
	      });
	    },
   };
	
	//判断省、市、区是否为空
	function ifNull(str){
		if(str.indexOf('请选择')!=-1){
			return str="";
		}else 
			return str;
	}

    //开始日期
    var insStart = laydate.render({
      elem: '#test-laydate-start'
     ,max:0
      /* ,min: 0 */
      ,done: function(value, date){
        //更新结束日期的最小日期
        insEnd.config.min = lay.extend({}, date, {
      	month: date.month - 1
        });
        
        //自动弹出结束日期的选择器
       insEnd.config.elem[0].focus();
      }
    });
    
    //结束日期
    var insEnd = laydate.render({
      elem: '#test-laydate-end'
      ,max:0
     /*  ,min: 0 */
      ,done: function(value, date){
        //更新开始日期的最大日期
        insStart.config.max = lay.extend({}, date, {
          month: date.month - 1
        });
      }
    });
	
   
   $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
     var type = $(this).data('type');
     active[type] ? active[type].call(this) : '';
   });
	

 //监听工具条
   table.on('tool(table)', function(obj){
     var data = obj.data;
     if(obj.event === 'review'){
         var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
         layer.open({
           type: 2
           ,title: '申请处理'
           ,content: Feng.ctxPath + '/auth/auth_review/1/'+data.authId
           ,area: ['890px','490px']
           ,btn: ['确定', '取消']
           ,yes: function(index, layero){
             var iframeWindow = window['layui-layer-iframe'+ index]
             ,submitID = 'auth-submit'
             ,submit = layero.find('iframe').contents().find('#'+ submitID);
             //监听提交
             iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
            	 var loadWait = layer.load(2);//加载层
            	 var field = data.field; //获取提交的字段
               var ajax = new $ax(Feng.ctxPath + "/auth/review", function (data) {
            	   layer.close(loadWait); //关闭加载
            	   Feng.success("处理成功!");
                   table.reload('table',{
                 	  done: function(res){
            		    	layer.close(loadingIndex);
            	          }
                    }); //数据刷新
                   layer.close(index); //关闭弹层
               }, function (data) {
            	   layer.close(loadWait); //关闭加载
                   Feng.error("处理失败!" + data.responseJSON.message + "!");
               },true);
               ajax.setData(field);
               ajax.start();
               
             });  
             
             submit.trigger('click');
           }
           ,btn2: function(index, layero){
      	   		layer.close(loadingIndex);
           }
           ,cancel:function(index, layero){
      	        layer.close(loadingIndex);
           }
         });
       }else if(obj.event === 'detail'){
       layer.open({
         type: 2
         ,title: '资质认证用户'
         ,content: Feng.ctxPath + '/auth/auth_review/2/'+data.authId
         ,area: ['890px', '490px']
         ,btn: ['取消']
         ,btn1: function(index, layero){
    	   layer.close(index);
         }
       });
     }
   });
});
</script>
@}
